package com.cinema;

import java.io.IOException;

import javax.jdo.JDOObjectNotFoundException;
import javax.jdo.PersistenceManager;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import query.DataQuery;

import com.cinema.data.Adminusr;
import com.cinema.data.PMF;
import com.cinema.data.User;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

public class Adminlogin extends HttpServlet{

	/**
	 * 
	 */
	public Adminlogin(){
		super();
	}
	private static final long serialVersionUID = 4010782057746594985L;
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		doPost(req, resp);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String username = request.getParameter("ftp-user-name");
		String password = request.getParameter("ftp-password");
		Boolean isAuth = false;
		DataQuery query = new DataQuery();
		Adminusr usr = query.checkAdmin(username, password);
		if(usr != null){
			HttpSession session = request.getSession();
			session.setAttribute("adminuser", usr);
			if(usr.getGroupid() == 1)
				response.sendRedirect("cp.jsp");
			else
				response.sendRedirect("/ticket?pageid=1");
		}else{
			response.sendRedirect("index.jsp");
		}
	}
}